const express = require('express');
const axios = require('axios');
const app = express();
app.use(express.static('public'));

app.get('/api/data', async (req, res) => {
  try {
    const response = await axios.post('http://clickhouse:8123/', null, {
      params: {
        query: 'SELECT dt, page, pv, uv FROM web_analytics ORDER BY dt DESC LIMIT 20 FORMAT JSON'
      }
    });
    res.json(response.data.data);
  } catch (err) {
    console.error(err);
    res.status(500).send('Error querying ClickHouse');
  }
});
app.listen(3000, () => console.log('Frontend running on http://localhost:3000'));
